/*******************************************************************************
 * Copyright (c) 2011 Grupo de Sistemas Inteligentes (GSI) - DIT UPM
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package es.upm.dit.gsi.eclipse.jadex.adfmanager.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import es.upm.dit.gsi.eclipse.jadex.adfmanager.wizards.CapabilityWizard;

/**
 * 
 * This action is placed in the ADF files context menu. It's able to start the new 
 * plan wizard in order to add a new plan to the selected agent.
 * 
 * @author Pablo Muñoz
 * 
 */

public class NewCapability implements IActionDelegate {
	private ISelection _selection;
	private Shell shell;
	WizardDialog dialog;
	CapabilityWizard wizard;

	/**
	 * Constructor for the AddCapabilityAction.
	 */
	public NewCapability() {
		super();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		if (_selection != null ) {
			wizard = new CapabilityWizard(_selection);
			shell = new Shell();
			dialog = new WizardDialog( shell, wizard );
			dialog.open();
			}
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
		_selection = selection;
	}
}
